<?php

class TagsSuggest extends CActiveRecord {

    public static function model($className = __CLASS__) {
        return parent::model($className);
    }

    public function tableName() {
        return 'TagsSuggest';
    }

    public static function links($item_id, $ids) {
        foreach($ids as $id) {
            $ts = new TagsSuggest();
            $ts->item_id = $item_id;
            $ts->tag_id = $id;
            $ts->save();
        }
    }

    static public function getItemIds($tags_ids) {
        $criteria = new CDbCriteria();
        $criteria->addInCondition("tag_id", $tags_ids);
        $items = TagsSuggest::model()->findAll($criteria);
        $ids = array();
        foreach($items as $item) {
            $ids[] = $item->item_id;
        }
        return $ids;
    }
}
